/**
 * 作者: hwp
 * 日期: 2025-05-12 15:08:23
 * 备注: 联盟大礼进度表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.server.game.base.LockKey;
import com.motu.monstercity.server.game.logic.UnionManager;
import com.motu.vertx.module.utility.main.MainService;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import io.vertx.core.json.JsonObject;
import io.vertx.core.shareddata.Lock;

public class UnionBoxInfo extends UnionBoxInfoModel {
    public UnionBoxInfo() {
        super();
    }

    public UnionBoxInfo(long unionId, int unionLevel) {
        int boxId = UnionManager.getUnionBoxCurrentBoxId(unionLevel);
        putId(unionId);
        putBoxId(boxId);
        putTotalNum(0);
        putProgress(0);
        putBoxNumRecord("");
    }

    public JsonObject insert() {
        putResetTime(TimeUtils.getCurTime());
        return super.insert();
    }

    public void reset() {
        if (!TimeUtils.isToday(getResetTime())) {
            putAddValue(0);
            putResetTime(TimeUtils.getCurTime());
            update();
        }
    }


    public boolean  addProgress(int value, int unionLevel) {
        boolean result = false;
        int maxProgress = UnionManager.getUnionBoxMaxProgress(unionLevel);
        if (getProgress() + value >= maxProgress) {
            int diffValue = (getProgress() + value) % maxProgress;
            int diffNum = (getProgress() + value) / maxProgress;
            addTotalNum(diffNum);
            putProgress(diffValue);

            int newBoxId = UnionManager.getUnionBoxCurrentBoxId(unionLevel);
            if (getBoxId() != newBoxId) {
                putBoxId(newBoxId);
            }
            result = true;
        } else {
            addProgress(value);
        }
        return result;
    }
}
